<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: pipi
  Date: 2018/5/7
  Time: 21:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>报价</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/build/css/doc.css" media="all">
</head>
<body>
<div class="layui-form-item">
    <label class="layui-form-label">新增</label>
    <div class="layui-input-block site-block">
        <form class="layui-form" action="/user/add" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" id="username" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input id="password" type="password" name="password" required
                           lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户级别</label>
                <div class="layui-input-block">
                    <select id="grade" name="grade" lay-verify="" lay-search>
                        <option value="1" selected="selected">管理员</option>
                        <option value="2">普通用户</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/plugins/layui/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        $ = layui.jquery;
        //监听提交
        form.on('submit(formDemo)', function(data){
            // layer.msg(JSON.stringify(data.field));
            console.log(data);
            $.ajax({
                type: "POST",  //提交方式
                url: "/user/add",//路径
                data: {
                    "username": $("#username").val(),
                    "password": $("#password").val(),
                    "grade": $("#grade").val(),
                },//数据，这里使用的是Json格式进行传输
                dataType: "json", //返回类型为json
                success: function (result) {//返回数据根据结果进行相应的处理
                    if (result.status == "true") {
                        window.location.href = "/user/list";
                    } else {
                        layer.msg(result.msg);
                    }
                }
            });
            return false;

        });
    });
</script>
</body>
</html>
